package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.UnregisterDto;
import com.huaxiafinance.management.service.UnregisterService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * Created by huangwencheng on 2017/11/8.
 */

@Controller("unregisterController")
@RequestMapping("/unregister")
public class UnregisterController {

  private static final Logger log = Logger.getLogger(UnregisterController.class);

  @Autowired
  private UnregisterService unregisterService;

  /**
   * 好友邀请查询
   *
   * @param dto 请求查询参数
   */
  @RequestMapping(value = "/queryUnregister", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryUnregister(@Valid @RequestBody UnregisterDto dto, BindingResult bindingResult) {
    log.info("好友邀请查询请求参数=======================>" + dto.toString());
    MessageResult messageResult = new MessageResult();

    try {
      if (bindingResult.hasErrors()) {
        messageResult.setFailureResult(bindingResult);
      } else {
        messageResult = unregisterService.queryUnregister(dto);
      }
    } catch (Exception e) {
      log.info("好友邀请查询异常原因=======================>" + e);
      messageResult.setFailureResult("系统异常");
    }

    log.info("好友邀请查询返回参数=======================>" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }

  /**
   * 请求渠道列表
   */
  @RequestMapping(value = "/queryChannelList", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryChannelList() {
    MessageResult messageResult = new MessageResult();
    try {
      messageResult = unregisterService.queryChannelList();
    } catch (Exception e) {
      log.info("请求渠道列表异常原因=======================>" + e);
      messageResult.setFailureResult("系统异常");
    }

    log.info("请求渠道列表返回参数=======================>" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }


}
